<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Json</title>
</head>

<body>

</body>

<script>
    //自定义对象
    // var user = {
    //     name: "Tom",
    //     age: 10,
    //     gender: "male",
    //     eat: function(){
    //          console.log("用膳~");
    //      }
    // }

    // console.log(user.name);
    // user.eat();

    var jsonStr = '{"name":"Tom", "age":18, "addr":["北京","上海","西安"]}';
    alert(jsonStr.name);

    //json字符串--js对象
    var obj = JSON.parse(jsonStr);
    alert(obj.name);

    //js对象--json字符串
    alert(JSON.stringify(obj));
</script>

</html>